from django.shortcuts import render
from django.views.generic import View
from .forms import MessageBoardForm, MyForms
from django.http import HttpResponse
from django.forms.utils import ErrorDict


class IndexView(View):
    def get(self, request):
        form = MessageBoardForm()
        return render(request, "index.html", context={"content":form})

    def post(self, request):
        a = MessageBoardForm(request.POST)
        if a.is_valid():
            title = a.cleaned_data.get('title')
        else:
            print(a.errors.get_json_date())
        return HttpResponse("hello")


class Index2(View):
    def get(self, request):
        return render(request, "index1.html")

    def post(self, request):
        form = MyForms(request.POST)
        if form.is_valid():
            return HttpResponse('success')
        else:
            print(form.errors.get_json_data())
            return HttpResponse('fail')